package com.rui.study.algorithm.BinarySearch_1_二分查找;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2018-11-12 14:15
 **/
public class BinarySearch1 {

    /**
     * 二分查找：
     * @param a
     * @param value
     * @return
     */
    public static int search(int[] a, int value) {
        int low = 0;
        int high = a.length - 1;
        while (low <= high) {
            int mid = low + ((high - low) >> 1);
            if (a[mid] < value) {
                low = mid + 1;
            } else if (a[mid] > value) {
                high = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

}
